/**
 * create ns if not already done
  */
var net = net || {};
net.andersand = net.andersand || {};

net.andersand.test = {
    
    /**
     * Defines a runnable test. The test can choose to throw an exception to fail by itself, or
     * use the <code>expected</code> parameter and return the actual value of what's being tested,
     * and this will be asserted here (unless expected === undefined, so just don't use undefined...)
     *
     * @param {function} fnTest
     * @param expected can be anything, except undefined
     */
    Test : function (scenarioName, fnTest, expected) {
        var logger = net.andersand.util.logger;
        /**
         * @return {boolean} true when test passed, false when test failed or exception was raised
         */
        this.run = function() {
            try {
                var actual = fnTest();
                if (expected !== undefined && expected !== actual) {
                    logger.log("Test failed [ " + scenarioName + " ] expected: (" + expected + ") but got (" + actual + ")");
                    return false;
                }
                logger.log("Test successful [ " + scenarioName + " ]", "success");
                return true;
            }
            catch (e) {
                logger.log(e.name + " - " + e.message, "error");
                return false;
//                throw e; // leads to strange debugger behavior in chrome
            }
        };
    }
};
